package cn.dengta.webapp.user.entity;

import java.util.Arrays;
import java.util.Date;

import cn.dengta.common.model.*;
import cn.dengta.context.model.*;
import cn.dengta.webapp.base.entity.BizEntity;
import cn.dengta.webapp.user.model.Gender;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.X;

/**
 * 意见反馈
 *
 * @author lgy
 * @since 2022-02-26
 */
@Getter
@Setter
public class Feedback extends BizEntity {

	public static final int PHOTO_UPLOAD_MAX = 5;

	/** 用户ID */
	private Long userId;
	/** 类型 */
	private FeedbackType type;
	/** 操作备注 */
	private String remark;
	/** 图片 */
	private String images;
	private WesKit wesKit;
	/** 性别 */
	public transient Gender gender;
	/** 昵称 */
	public transient String nickname;

	public Feedback init(Feedback input, Date now) {
		this.userId = X.expectNotNull(userId, input.userId);
		this.type = X.expectNotNull(input.type, type);
		this.remark = X.expectNotNull(input.remark, remark);
		this.images = X.expectNotNull(input.images, images);
		this.wesKit = X.expectNotNull(input.wesKit, wesKit);
		super.init(VerifyStatus.WAIT_VERIFY.value, State.PUBLIC);
		super.initTime(now);
		return this;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Getter
	public enum FeedbackType implements LabelI18nProxy<FeedbackType, Integer> {
		/** 问题 */
		PROBLEM(0, UserEnumI18nKey.FEEDBACK_TYPE_PROBLEM),
		/** 建议 */
		ADVISE(1, UserEnumI18nKey.FEEDBACK_TYPE_ADVISE),
		//
		;

		// 定义私有变量
		public final Integer value;
		/** 是否在客户端显示 */
		public final Boolean show;
		final ValueProxy<FeedbackType, Integer> proxy;

		public static final FeedbackType[] SHOW_CACHE = Arrays.stream(values()).filter(FeedbackType::getShow).toList().toArray(FeedbackType[]::new);

		// 构造函数，枚举类型只能为私有
		FeedbackType(Integer value, String label, Boolean show) {
			this.value = value;
			this.show = show;
			this.proxy = new ValueProxy<>(this, value, label);
		}

		FeedbackType(Integer value, String label) {
			this(value, label, true);
		}

		public static FeedbackType[] getValues() {
			return ValueProxy.getCachedArray(FeedbackType.class, FeedbackType::values);
		}

		public static FeedbackType of(Integer value) {
			return PROBLEM.getValueOf(value);
		}
	}

}
